package it.webrules.deploymanager.core.dy.deploy;

import java.io.IOException;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;

/**
 * 
 * Interface for JMX server connection
 * 
 * @author dometec
 *
 */
public interface MBeanManager {

	void findAJPConnector() throws MalformedObjectNameException, IOException, MBeanException, AttributeNotFoundException,
			InstanceNotFoundException, ReflectionException, DeployException;

	ObjectName getAJPGlobalRequestProcessorObjectName() throws MalformedObjectNameException, IOException, MBeanException,
			AttributeNotFoundException, InstanceNotFoundException, ReflectionException;

	void pauseAJP() throws InstanceNotFoundException, MBeanException, ReflectionException, IOException, MalformedObjectNameException,
			AttributeNotFoundException;

	void stopAJP() throws InstanceNotFoundException, MBeanException, ReflectionException, IOException, MalformedObjectNameException,
			AttributeNotFoundException;

	void resumeAJP() throws InstanceNotFoundException, MBeanException, ReflectionException, IOException, MalformedObjectNameException,
			AttributeNotFoundException, DeployException;

	void startAJP() throws InstanceNotFoundException, MBeanException, ReflectionException, IOException, MalformedObjectNameException,
			AttributeNotFoundException, DeployException;

	/**
	 * 
	 * Wait until all request are finished
	 * 
	 * @param timeout sec before going to timeout
	 * @return true when all request are done, false on timeout
	 * @throws NullPointerException 
	 * @throws MalformedObjectNameException 
	 * @throws IOException 
	 * @throws InterruptedException 
	 * @throws ReflectionException 
	 * @throws MBeanException 
	 * @throws InstanceNotFoundException 
	 * @throws AttributeNotFoundException 
	 */
	boolean waitForProcessingAllRequest(Integer timeout) throws MalformedObjectNameException, NullPointerException, IOException,
			InterruptedException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException;

	void undeploy(String virtualhost, String contextname) throws MalformedObjectNameException, NullPointerException, IOException,
			InstanceNotFoundException, MBeanException, ReflectionException, DeployException;

	boolean isDeployed(String virtualhost, String contextname) throws MalformedObjectNameException, NullPointerException, IOException,
			InterruptedException, DeployException;

	void waidUndeploy(String virtualhost, String contextname, Integer timeout) throws MalformedObjectNameException, NullPointerException,
			IOException, InterruptedException, DeployException;

	void waidDeploy(String virtualhost, String contextname, Integer timeout) throws MalformedObjectNameException, NullPointerException,
			IOException, InterruptedException, DeployException;

	boolean isAvailable();

	Object getMBeanValue(String objectName, String attribute) throws Exception;

	Object getMBeanValue(String objectName, String attribute, String subattribute) throws Exception;

}